from __future__ import division
from sympy import symbols, sqrt, diff, acos


x1, y1, z1, x2, y2, z2 = symbols('x1 y1 z1 x2 y2 z2')

r1 = sqrt(x1*x1 + y1*y1 + z1*z1)
r2 = sqrt(x2*x2 + y2*y2 + z2*z2)

cosa = (x1*x2+y1*y2+z1*z2)/r1/r2
cosa = acos(cosa)

dx2 = [[0] * 6 for i in range(6)]

dx2[0][0] = cosa.diff(x1, x1)
dx2[0][1] = cosa.diff(x1, y1)
dx2[0][2] = cosa.diff(x1, z1)
dx2[0][3] = cosa.diff(x1, x2)
dx2[0][4] = cosa.diff(x1, y2)
dx2[0][5] = cosa.diff(x1, z2)

dx2[1][0] = cosa.diff(y1, x1)
dx2[1][1] = cosa.diff(y1, y1)
dx2[1][2] = cosa.diff(y1, z1)
dx2[1][3] = cosa.diff(y1, x2)
dx2[1][4] = cosa.diff(y1, y2)
dx2[1][5] = cosa.diff(y1, z2)

dx2[2][0] = cosa.diff(z1, x1)
dx2[2][1] = cosa.diff(z1, y1)
dx2[2][2] = cosa.diff(z1, z1)
dx2[2][3] = cosa.diff(z1, x2)
dx2[2][4] = cosa.diff(z1, y2)
dx2[2][5] = cosa.diff(z1, z2)

dx2[3][0] = cosa.diff(x2, x1)
dx2[3][1] = cosa.diff(x2, y1)
dx2[3][2] = cosa.diff(x2, z1)
dx2[3][3] = cosa.diff(x2, x2)
dx2[3][4] = cosa.diff(x2, y2)
dx2[3][5] = cosa.diff(x2, z2)

dx2[4][0] = cosa.diff(y2, x1)
dx2[4][1] = cosa.diff(y2, y1)
dx2[4][2] = cosa.diff(y2, z1)
dx2[4][3] = cosa.diff(y2, x2)
dx2[4][4] = cosa.diff(y2, y2)
dx2[4][5] = cosa.diff(y2, z2)

dx2[5][0] = cosa.diff(z2, x1)
dx2[5][1] = cosa.diff(z2, y1)
dx2[5][2] = cosa.diff(z2, z1)
dx2[5][3] = cosa.diff(z2, x2)
dx2[5][4] = cosa.diff(z2, y2)
dx2[5][5] = cosa.diff(z2, z2)

data = {'x1':0.0, 'y1':0.81130000000000002, 'z1':0.6069, 'x2':0.0, 'y2':-0.78980000000000006, 'z2':0.63450000000000006}
for i in range(6):
    for j in range(6):
        print "%10.5f" % dx2[i][j](data), 
    print 

